<template>
	<public-view navType="getwork" navTitle="招聘">
		<view class="content">
			<view class="">
				<top-select :list="top_tab" :isAround="false"  @backData="showPopup"></top-select>
			</view>
			<view class="w-100 margin-aa">
				<block v-for="(item, index) in list" :key="index">
					<work-box :item="item"></work-box>
				</block>
			</view>
			<picker-type :pickerType="pickerType" ref="showpikcer" @classBack="classBack"></picker-type>
		</view>
	</public-view>
</template>

<script>
	import topSelect from "@/components/myComponents/topSelect.vue"
	import workBox from "@/components/myComponents/workBox.vue"
	import pickerType from "@/components/myComponents/pickerViewClass.vue"
	export default {
		components:{
			'top-select':topSelect,
			"work-box":workBox,
			"picker-type":pickerType
		},
		watch:{
			"$store.state.work_id":{
				handler(nval,oval){
					this.page = 1
					this.list = []
					this.getWorkList()
				}
			}
		},
		data() {
			return {
				top_tab:[
					// {
					// 	id:'1',
					// 	is_active:true,
					// 	title:"工作地"
					// },
					{
						id:'2',
						is_active:true,
						title:"车型",
						children_name:""
					},
					{
						id:'3',
						is_active:true,
						title:"薪资",
						children_name:""
					}
				],
				page:1,
				list:[],
				model:[],
				top_tab_index:1,
				pickerType:'2',
				salary:{
					start:"",
					end:""
				}
			};
		},
		onReachBottom() {
			this.page++
			this.getWorkList()
		},
		onShow() {
			this.$setNotice()
			this.getWorkList()
		},
		onPullDownRefresh() {
			this.page = 1
			this.list = []
			this.getWorkList()
		},
		methods:{
			classBack(e){
				console.log(e,"that.class_list")
				if(this.pickerType === '2'){
					if(e.id == 0){
						this.model = []
					}else{
						this.model[0] = e.id ||""
					}
					this.page = 1
					this.list = []
					this.top_tab[this.top_tab_index].children_name = e.name ||""
				}
				if(this.pickerType === '3'){
					let arr = e.money.split('-')
					!!!Number(arr[1]) && (arr[1] = "")
					this.salary = {
						"start":arr[0],
						"end":arr[1]
					}
				}
				this.getWorkList()
			},
			showPopup(o){
				this.top_tab_index = o.index
				this.pickerType = o.item?.id
				if(o.item?.id === '2' || o.item?.id === '3'){
					this.$refs.showpikcer.show()
				}
				// if(o.item.id === '2'){
					
				// }
			},
			getWorkList(){
				let that = this
				console.log(that.$store.state.work_id)
				that.util.postRequest({
					url:"v1/content/work",
					data:{
						type:that.$store.state.work_id,
						keyword:"",
						model:that.model,
						salary:{
							"start":that.salary.start,
							"end":that.salary.end
						},
						page:that.page
					}
				}).then(res=>{
					console.log(res)
					if(that.page === 1){
						that.list = res.data.data
					}else{
						if(res.data.data.length>0){
							that.list = that.list.concat(res.data.data)
						}else{
							that.page--
						}
					}
					uni.stopPullDownRefresh()
				}).catch(e=>{
					uni.stopPullDownRefresh()
				})
			},
		}
	}
</script>

<style lang="scss">
	.margin-aa{
		margin-top: 36upx;
	}
	.top-select-view{
		width: 100%;
		margin-bottom: 36upx;
		.item{
			.icon{
				width: 20upx;
				height: 20upx;
				margin-left: 8upx;
			}
		}
	}
	.content{
		width: 750upx;
		padding: 36upx 24upx;
	}
</style>
